<?php
class Project_model extends CI_Model {
        
    public function __construct()
    {
        parent::__construct();
        $this->load->model('query_project');
    
    }
    
    public function get_project(){
         
         $sql = "SELECT pro_id,name,hireday,description,bucket,mgr_id,est_endday,end_day FROM ".$this->config->item('schema').".project";
         return $this->query_project->select_query($sql);
    }

    public function get_project_by_id($id){
         
         $sql = "SELECT pro_id,name,hireday,description,bucket,mgr_id,est_endday,end_day FROM ".$this->config->item('schema').".project where pro_id='".$id."'";
         return $this->query_project->select_query($sql);
    }
  
    public function update_project($data ){
        $this->session->set_flashdata('type', 'update');
        $this->session->set_flashdata('table', 'Project');
        $sql = "UPDATE ".$this->config->item('schema').".Project
                    SET 
                         name='".$data['name']."'"
                         . ",hireday='".$data['hireday']."'"
                         . ",description='".$data['description']."'"
                         . ",bucket='".$data['bucket']."'"
                         . ",mgr_id='".$data['mgr_id']."'"
                         . ",est_endday='".$data['est_endday']."'"
                         . ",end_day='".$data['end_day']."'"
                  . "WHERE pro_id='".$data['pro_id']."'";
                
                     
        return $this->query_project->update_query($sql);
   } //End # update project

  public function  store_project($data){
      $this->session->set_flashdata('type', 'add');
        $this->session->set_flashdata('table', 'Project');
         $sql = "INSERT INTO ".$this->config->item('schema').".project(pro_id,name,hireday,description,bucket,mgr_id,est_endday,end_day)"
                . "VALUES ('".$data['pro_id']."','".$data['name']."','".$data['hireday']."','".$data['description']."','".$data['bucket']."'"
                . ",'".$data['mgr_id']."','".$data['est_endday']."','".$data['end_day']."')" ;            

         return $this->query_project->update_query($sql);
    }


    public function delete_project($id){
        $this->session->set_flashdata('type', 'del');
        $this->session->set_flashdata('table', 'Project');
        $sql = "DELETE FROM ".$this->config->item('schema').".PROJECT WHERE pro_id='".$id."'";
         return $this->query_project->update_query($sql);
    } // End # delete_employee

    
      public function update_af_in_project($data){
         $this->session->set_flashdata('type', 'update');
         $this->session->set_flashdata('table', 'Project');
        $sql = "UPDATE ".$this->config->item('schema').".project
                    SET 
                      ".$data['af_pro_field']."=".$data['af_value']." "
                       . "WHERE pro_id='".$data['af_pro_id']."'";
        return $this->query_project->update_query($sql);
    }
    
}